package jp.reflexworks.invoice;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;

import jp.reflexworks.invoice.model.Invoice;
import jp.reflexworks.invoice.model.Order;

public class Instance {

	public static Invoice getUpdateInvoice() {

		Invoice invoice = new Invoice();

		// primary key
		invoice.id = 1;
		
		invoice.revision = 0;
		invoice.invoiceNo = "MNS2009040";
		invoice.companyName = "(株)　PDFサービス";
		invoice.job = "更新プロジェクト";

		return invoice;
		
	}
	
	public static Invoice newInvoice(long i) {
		
		Invoice invoice = new Invoice();
		
		String suffix = "_" + String.format("%03d", i);
		
		String _invoiceNo = "MNS200904" + suffix;
		
		invoice.setInvoiceNo(_invoiceNo);
		
		
		Calendar cal = Calendar.getInstance();
		// 10個おきに日付が変わる
		cal.add(Calendar.DATE,(int) i/10);
		DateFormat dfm = new SimpleDateFormat("yyyy/MM/dd");

		invoice.issuedDate = dfm.format(cal.getTime());
//		invoice.companyName = "(株)　クラウドサービス" + suffix;
//		invoice.job = "PDF帳票システム検証プロジェクト" + suffix;

		invoice.companyName = "companyName" + suffix;
		invoice.job = "job" + suffix;

		invoice.order = new ArrayList<Order>();
		
		for (int j = 0; j < i; j++) {
			//Orderの件数をランダムにする場合
//			java.util.Random rnd = new java.util.Random();
//			int num = rnd.nextInt(10)+1;
			
			
			int num = (int) i;
			
			int quiantity = num;
			int unitPrice = num * 10;
			int lineTotal = unitPrice * quiantity;
			
			for (int k = 0; k < num; k++) {
				Order order = new Order();
				order.setInvoiceNo(_invoiceNo);
				order.seqno       = "" + (j + 1);
				order.description = "品名_" + String.format("%03d", j);
				order.quantity    = "1";
				order.unitPrice   = ""+unitPrice;
				order.lineTotal   = ""+lineTotal;
				order.productcd   = "productcd_" + String.format("%04d", j);
				
				invoice.order.add(order);	
			}
		}
		
		invoice.convertFrom();
		
		invoice.note1 = "①　お支払日：2008年8月末日までにお支払いください。";

		return invoice;
	}

	public static Invoice newInvoiceForUpdate(long i) {
		
		Invoice invoice = new Invoice();
		
		String suffix = "_" + String.format("%03d", i);
		
		String _invoiceNo = "MNS200904" + suffix;
		
		invoice.setInvoiceNo(_invoiceNo);
		
		
		Calendar cal = Calendar.getInstance();
		// 10個おきに日付が変わる
		cal.add(Calendar.DATE,(int) i/10);
		DateFormat dfm = new SimpleDateFormat("yyyy/MM/dd");

		invoice.issuedDate = dfm.format(cal.getTime());
		invoice.companyName = "(株)UPDATEクラウドサービスUPDATE" + suffix;
		invoice.job = "PDF帳票システム検証プロジェクト" + suffix;
		
		invoice.order = new ArrayList<Order>();
		
		for (int j = 0; j < i; j++) {
			java.util.Random rnd = new java.util.Random();
			int num = rnd.nextInt(10)+1;
			
			
			//mura
			num = (int) 1;
			
			int quiantity = num;
			int unitPrice = num * 10;
			int lineTotal = unitPrice * quiantity;
			
			for (int k = 0; k < num; k++) {
				Order order = new Order();
				order.setInvoiceNo(_invoiceNo);
				order.seqno       = "" + (j + 1);
				order.description = "UPDATe_" + k + "_品名_" + String.format("%03d", j);
				order.quantity    = "1";
				order.unitPrice   = ""+unitPrice;
				order.lineTotal   = ""+lineTotal;
				order.productcd   = "productcd_" + String.format("%04d", j);
				
				invoice.order.add(order);	
			}
		}
		
		invoice.convertFrom();
		
		invoice.note1 = "①　お支払日：2008年8月末日までにお支払いください。";

		return invoice;
	}


}
